const app = getApp(),
      api = require("../../../utils/api.js"),
      request = require("../../../service/request.js");
var page = 0,
    page1 = 0;

Page( {  
  data: {  
    /*页面配置 */  
    winWidth: 0,  
    winHeight: 0,  
    currentTab: 0,// tab切换 
  },
  onShow() { //返回显示页面状态函数
    this.onLoad()//再次加载，实现返回上一页页面刷新
  },
   
  onLoad: function() {  
    var that = this;
    request.get(`${api.getInfoCollectionList}?page=${page}`, {}, app.globalData.sessionid).then(res => {
      that.setData({
        scInfoList: res.data
      });
      console.log(that.data.scInfoList);
      request.get(`${api.getExpCollectionList}?page=${page1}`, {}, app.globalData.sessionid).then(res => {
        that.setData({
          scExpList: res.data
        });
        console.log(that.data.scExpList);
      })
    })
    wx.getSystemInfo( {  
  
      success: function( res ) {  
        that.setData( {  
          winWidth: res.windowWidth,  
          winHeight: res.windowHeight  
        });  
      }  
  
    });

   },
   
   
    /** 
       * 滑动切换tab 
       */  
  bindChange: function(e) {  
  
    var that = this;  
    that.setData( { currentTab: e.detail.current });  
  
  },  
  /** 
   * 点击tab切换 
   */  
  swichNav: function( e ) {  
  
    var that = this;  
  
    if( this.data.currentTab === e.target.dataset.current ) {  
      return false;  
    } else {  
      that.setData( {  
        currentTab: e.target.dataset.current  
      })  
    }  
  },
  

  //触底加载更多
  pullUpLoad: function() {
    var that = this; 
    
    console.log(1);
    if (that.data.currentTab===0) {
      page++;

      request.get(`${api.getInfoCollectionList}?page=${page}`, {}, app.globalData.sessionid).then(res => {
        var isBottom = (!res.data.length==0)?true:false;
        if(isBottom){
          wx.showLoading({
            title: '加载更多数据',
            icon: 'loading',
            duration:2000
          })
          var moment_list = that.data.scInfoList;
          for (var i = 0; i < res.data.length; i++) {
            moment_list.push(res.data[i]);
          }

          that.setData({
            scInfoList:moment_list
          })
          wx.hideLoading();
          console.log("收藏校招信息加载page="+page);
          console.log(res.data);
        } else {
          wx.showToast({
            title: '没有更多了(╥﹏╥)',
            icon: 'none',
            duration:2000
          })
        }
      })
    } else if(that.data.currentTab===1) {
        page1++;
        request.get(`${api.getExpCollectionList}?page=${page1}`, {}, app.globalData.sessionid).then(res => {
          // console.log(res.data);
          var isBottom = (!res.data.length==0)?true:false;
          if(isBottom){
            wx.showLoading({
              title: '加载更多数据',
              icon: 'loading',
              duration:2000
            })
            var moment_list = that.data.scExpList;
     
            for (var i = 0; i < res.data.length; i++) {
              moment_list.push(res.data[i]);
            }

            that.setData({
              scExpList:moment_list
            })
            //that.randomColor1();
            wx.hideLoading();
            console.log("收藏面经加载page="+page1);
            console.log(res.data);
          } else {
            wx.showLoading({
              title: '亲，到底啦！',
              icon: 'none',
              duration:1000
            })
            page1--;
            console.log("收藏面经加载page="+page1);
          }
        })
      } 
    
    }


  //分享

  // onReady: function (e) { 
  //   wx.showShareMenu({ 
  //     withShareTicket:true 
  //   }); 
  // },
  // onShareAppMessage: function () {
  //   let that = this;
  //   return {
  //     title: '校招SSP', // 转发后 所显示的title
  //     path: '/pages/find/find', // 相对的路径
  //     success: (res)=>{    // 成功后要做的事情
  //       console.log(res)
  //       console.log(res.shareTickets[0])
  //       wx.showToast({
  //         title:"分享成功^O^",
  //         icon:"success",
  //         duration:2500
  //       });
  //       wx.getShareInfo({
  //         shareTicket: res.shareTickets[0],
  //         success: (res)=> { 
  //           // that.setData({
  //           //   isShow:true
  //           // }) 
  //           // console.log(that.setData.isShow)
  //           console.log("2"+res.data)
  //          },
  //         fail: function (res) { console.log("失败"+res) },
  //         complete: function (res) { console.log("成功"+res) }
  //       })
  //     },
  //     fail: function (res) {
  //       // 分享失败
  //       console.log(res)
  //     }
  //   }
  // }

  
})